package io.renren.modules.aic.controller;

import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.common.validator.ValidatorUtils;
import io.renren.modules.aic.entity.PriceBookEntity;
import io.renren.modules.aic.service.PriceBookService;

import java.util.Arrays;
import java.util.Date;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 价格走势表
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2018-05-03 16:31:26
 */
@RestController
@RequestMapping("aic/pricebook")
public class PriceBookController {
	@Autowired
	private PriceBookService priceBookService;

	/**
	 * 列表
	 */
	@RequestMapping("/list")
	@RequiresPermissions("aic:pricebook:list")
	public R list(@RequestParam Map<String, Object> params) {
		PageUtils page = priceBookService.queryPage(params);
		return R.ok().put("page", page);
	}

	/**
	 * 信息
	 */
	@RequestMapping("/info/{id}")
	@RequiresPermissions("aic:pricebook:info")
	public R info(@PathVariable("id") Long id) {
		PriceBookEntity priceBook = priceBookService.selectById(id);
		return R.ok().put("priceBook", priceBook);
	}

	/**
	 * 保存
	 */
	@RequestMapping("/save")
	@RequiresPermissions("aic:pricebook:save")
	public R save(@RequestBody PriceBookEntity priceBook) {
		// 校验类型
		ValidatorUtils.validateEntity(priceBook);
		priceBook.setCreateTime(new Date());
		priceBookService.insert(priceBook);
		return R.ok();
	}

	/**
	 * 修改
	 */
	@RequestMapping("/update")
	@RequiresPermissions("aic:pricebook:update")
	public R update(@RequestBody PriceBookEntity priceBook) {
		// 校验类型
		ValidatorUtils.validateEntity(priceBook);
		priceBookService.updateById(priceBook);
		return R.ok();
	}

	/**
	 * 删除
	 */
	@RequestMapping("/delete")
	@RequiresPermissions("aic:pricebook:delete")
	public R delete(@RequestBody Long[] ids) {
		priceBookService.deleteBatchIds(Arrays.asList(ids));

		return R.ok();
	}

}
